package com.own.component.util.database.handler;

import com.own.component.common.model.ExceptionMessageModel;
import com.own.component.util.database.exception.DatabaseException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * DatabaseExceptionHandler
 *
 * @author chenxueli
 * @date 2022-10-15 14:13:51
 */
@Slf4j
@Order(1)
@RestControllerAdvice
public class DatabaseExceptionHandler {

    /**
     * 处理 DatabaseException 异常
     *
     * @param e 异常信息
     * @return 返回信息
     */
    @ExceptionHandler(DatabaseException.class)
    public ExceptionMessageModel handleElasticException(DatabaseException e) {
        log.error(e.getMessage());
        return new ExceptionMessageModel(e);
    }

}
